package com.guoliang.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guoliang.commonUtils.CommonResult;
import com.guoliang.eduService.entity.EduCourse;
import com.guoliang.eduService.entity.EduTeacher;
import com.guoliang.eduService.service.EduCourseService;
import com.guoliang.eduService.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：Leo
 * @date ：Created in 2023/1/26 10:48
 * @description：
 */
@Api(description = "查询热门课程和名师")
@RestController
@RequestMapping("/eduService/indexfront")
public class IndexFrontController {
    @Autowired
    EduCourseService eduCourseService;
    @Autowired
    EduTeacherService eduTeacherService;

    @ApiOperation("查询前八个热门课程 前四个名师")
    @GetMapping("index")
    public CommonResult getIndex(){
        //查询前八个热门课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("buy_count");
        wrapper.last("limit 8");
        List<EduCourse> eduCourseList = eduCourseService.list(wrapper);
        //查询前四个名师
        QueryWrapper<EduTeacher> wrapper1=new QueryWrapper<>();
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 4");
        List<EduTeacher> eduTeacherList = eduTeacherService.list(wrapper1);

        return CommonResult.ok().data("courses",eduCourseList).data("teachers",eduTeacherList);
    }
}
